package chenji.StrongFossil.Puncher;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class Puncher {
	ItemStack item;
	int Durable;
	double addChange;
	ItemStack fullItem;

	public Puncher(ItemStack item, int Durable, double addChange) {
		this.item = item;
		this.addChange = addChange;
		this.Durable = Durable;
		if (item.hasItemMeta()) {
			if (item.getItemMeta().hasLore()) {
				List<String> lore = item.getItemMeta().getLore();
				lore.add("§c⇨" + this.Durable + "/" + this.Durable);
				ItemMeta m = item.getItemMeta();
				m.setLore(lore);
				this.fullItem = item.clone();
				this.fullItem.setItemMeta(m);
			}
		}
		if (this.fullItem == null) {
			this.fullItem = item.clone();
			ItemMeta m = item.getItemMeta();
			List<String> lore = new ArrayList<String>();
			m.setLore(lore);
			this.fullItem.setItemMeta(m);
		}
	}

	public ItemStack getFullItem() {
		return this.fullItem;
	}

	public boolean equals(ItemStack i) {
		if (i == null) {
			return false;
		}
		if (!(i.hasItemMeta())) {
			return false;
		}
		if (!(i.getItemMeta().hasLore())) {
			return false;
		}

		List<String> lore = i.getItemMeta().getLore();
		int index = 0;
		boolean hasDurable = false;
		for (String s : lore) {
			if (s.startsWith("§c⇨") && s.contains("/")) {
				hasDurable = true;
				lore.remove(index);
				break;
			}
			index++;
		}
		if (!(hasDurable)) {
			return false;
		}
		if (this.item.getItemMeta().getLore().equals(lore)
				&& this.item.getItemMeta().getDisplayName().equals(i.getItemMeta().getDisplayName())
				&& this.item.getType().equals(i.getType())) {
			return true;
		} else {
			return false;
		}
	}

	public int getDurable() {
		return this.Durable;
	}

	public ItemStack getItem() {
		return this.item;
	}

	public double getChange() {
		return this.addChange;
	}
}
